package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.business.Topic;
import com.lkd.config.TopicConfig;
import com.lkd.contract.VmStatusContract;
import com.lkd.service.TaskService;
import com.lkd.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Topic(TopicConfig.VMS_STATUS_TOPIC)
public class VMStatusHandler implements MsgHandler {

    @Autowired
    private TaskService taskService;
    /**
     * 接收消息
     * @param jsonMsg
     */
    @Override
    public void process(String jsonMsg) {
        log.info("接收到售货机上报状态，jsonMsg={}",jsonMsg);
        if(StringUtils.isBlank(jsonMsg)){
            return;
        }
        try {
//        转对象
            VmStatusContract statusContract = JsonUtil.getByJson(jsonMsg, VmStatusContract.class);
//            创建自动维修工单
            taskService.createRepairTaskAuto(statusContract);
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
